<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%@include file="../../common/include-header.jsp" %>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            科目名：
                            <select required name="courseId" id="courseId">
                                <option value="">请选择</option>
                            </select>
                        </li>
                        <li>
                            试卷名称：<input type="text" name="examName" />
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 批量删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true">

            </table>
        </div>
    </div>
</div>
<%@include file="../../common/include-footer.jsp" %>
<script th:inline="javascript">
    var prefix = "/testPaper";
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/findById/{id}",
            removeUrl: prefix + "/remove",
            sortName: "asc",
            height: 500,
            modalName: "试卷",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '试卷编号'
                },
                {
                    field: 'name',
                    title: '试卷名'
                },
                {
                    field: 'courseName',
                    title: '科目名称'
                },
                {
                    field: 'amount',
                    title: '题目数量'
                },
                {
                    field: 'duration',
                    title: '试卷持续时间（分钟）'
                },
                {
                    field: 'teacherName',
                    title: '出卷人'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    formatter:function(val, item, rowIndex){
                        var date = new Date(val);
                        var YY = date.getFullYear() + '-';
                        var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                        var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                        var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
                        var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
                        var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                        return YY + MM + DD +" "+hh + mm + ss;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + '" href="#" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        //科目下拉款初始化
        $.ajax({
            url:"${pageContext.request.contextPath}/course/findAll",    //请求的url地址
            dataType:"json",   //返回格式为json
            async:true,//请求是否异步，默认为异步，这也是ajax重要特性
            type:"POST",   //请求方式
            success:function(result){
                var list = result.data;
                for(var i=0;i<list.length;i++){
                    var courseId = list[i].id;
                    var courseName =list[i].name;
                    //给下拉框动态赋值
                    $("#courseId").append("<option value='"+courseId+"'>"+courseName+"</option>");
                }
            }
        });

    });

    // function showEditParam(id) {
    //     $.post(
    //         'testPaper/findById',
    //         {'id':id},
    //         function (result) {
    //             if(result.success){
    //
    //             }
    //         }
    //     );
    // }
</script>
</body>
</html>
